package com.bootdo.blog.dao;

import com.bootdo.blog.domain.PlotDO;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
/**
 * 
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2021-03-07 10:38:32
 */
@Mapper
public interface PlotMapper {

	@Select("select `plot_id`, `plot_number`, `plot_area`, `soil_classification`, `nutrient`, `planting_time`, `count`, `plant_spacing`, `before_old`, `old`, `pre_mu`, `production`, `frame_shape`, `tree`, `seed_id` from tb_plot where plot_id = #{id}")
	PlotDO get(Integer plotId);
	
	@Select("<script>" +
	"select * from tb_plot " + 
			"<where>" + 
		  		  "<if test=\"plotId != null and plotId != ''\">"+ "and plot_id = #{plotId} " + "</if>" + 
		  		  "<if test=\"plotNumber != null and plotNumber != ''\">"+ "and plot_number = #{plotNumber} " + "</if>" + 
		  		  "<if test=\"plotArea != null and plotArea != ''\">"+ "and plot_area = #{plotArea} " + "</if>" + 
		  		  "<if test=\"soilClassification != null and soilClassification != ''\">"+ "and soil_classification = #{soilClassification} " + "</if>" + 
		  		  "<if test=\"nutrient != null and nutrient != ''\">"+ "and nutrient = #{nutrient} " + "</if>" + 
		  		  "<if test=\"plantingTime != null and plantingTime != ''\">"+ "and planting_time = #{plantingTime} " + "</if>" + 
		  		  "<if test=\"count != null and count != ''\">"+ "and count = #{count} " + "</if>" + 
		  		  "<if test=\"plantSpacing != null and plantSpacing != ''\">"+ "and plant_spacing = #{plantSpacing} " + "</if>" + 
		  		  "<if test=\"beforeOld != null and beforeOld != ''\">"+ "and before_old = #{beforeOld} " + "</if>" + 
		  		  "<if test=\"old != null and old != ''\">"+ "and old = #{old} " + "</if>" + 
		  		  "<if test=\"preMu != null and preMu != ''\">"+ "and pre_mu = #{preMu} " + "</if>" + 
		  		  "<if test=\"production != null and production != ''\">"+ "and production = #{production} " + "</if>" + 
		  		  "<if test=\"frameShape != null and frameShape != ''\">"+ "and frame_shape = #{frameShape} " + "</if>" + 
		  		  "<if test=\"tree != null and tree != ''\">"+ "and tree = #{tree} " + "</if>" + 
		  		  "<if test=\"seedId != null and seedId != ''\">"+ "and seed_id = #{seedId} " + "</if>" + 
		  			"</where>"+ 
			" <choose>" + 
	            "<when test=\"sort != null and sort.trim() != ''\">" + 
	                "order by ${sort} ${order}" + 
	            "</when>" + 
				"<otherwise>" + 
	                "order by plot_id desc" + 
				"</otherwise>" + 
	        "</choose>"+
			"<if test=\"offset != null and limit != null\">"+
			"limit #{offset}, #{limit}" + 
			"</if>"+
			"</script>")
	List<PlotDO> list(Map<String, Object> map);
	
	@Select("<script>" +
	"select count(*) from tb_plot " + 
			"<where>" + 
		  		  "<if test=\"plotId != null and plotId != ''\">"+ "and plot_id = #{plotId} " + "</if>" + 
		  		  "<if test=\"plotNumber != null and plotNumber != ''\">"+ "and plot_number = #{plotNumber} " + "</if>" + 
		  		  "<if test=\"plotArea != null and plotArea != ''\">"+ "and plot_area = #{plotArea} " + "</if>" + 
		  		  "<if test=\"soilClassification != null and soilClassification != ''\">"+ "and soil_classification = #{soilClassification} " + "</if>" + 
		  		  "<if test=\"nutrient != null and nutrient != ''\">"+ "and nutrient = #{nutrient} " + "</if>" + 
		  		  "<if test=\"plantingTime != null and plantingTime != ''\">"+ "and planting_time = #{plantingTime} " + "</if>" + 
		  		  "<if test=\"count != null and count != ''\">"+ "and count = #{count} " + "</if>" + 
		  		  "<if test=\"plantSpacing != null and plantSpacing != ''\">"+ "and plant_spacing = #{plantSpacing} " + "</if>" + 
		  		  "<if test=\"beforeOld != null and beforeOld != ''\">"+ "and before_old = #{beforeOld} " + "</if>" + 
		  		  "<if test=\"old != null and old != ''\">"+ "and old = #{old} " + "</if>" + 
		  		  "<if test=\"preMu != null and preMu != ''\">"+ "and pre_mu = #{preMu} " + "</if>" + 
		  		  "<if test=\"production != null and production != ''\">"+ "and production = #{production} " + "</if>" + 
		  		  "<if test=\"frameShape != null and frameShape != ''\">"+ "and frame_shape = #{frameShape} " + "</if>" + 
		  		  "<if test=\"tree != null and tree != ''\">"+ "and tree = #{tree} " + "</if>" + 
		  		  "<if test=\"seedId != null and seedId != ''\">"+ "and seed_id = #{seedId} " + "</if>" + 
		  			"</where>"+ 
			"</script>")
	int count(Map<String, Object> map);
	
	@Insert("insert into tb_plot (`plot_number`, `plot_area`, `soil_classification`, `nutrient`, `planting_time`, `count`, `plant_spacing`, `before_old`, `old`, `pre_mu`, `production`, `frame_shape`, `tree`, `seed_id`)"
	+ "values (#{plotNumber}, #{plotArea}, #{soilClassification}, #{nutrient}, #{plantingTime}, #{count}, #{plantSpacing}, #{beforeOld}, #{old}, #{preMu}, #{production}, #{frameShape}, #{tree}, #{seedId})")
	int save(PlotDO plot);
	
	@Update("<script>"+ 
			"update tb_plot " + 
					"<set>" + 
		            "<if test=\"plotId != null\">`plot_id` = #{plotId}, </if>" + 
                    "<if test=\"plotNumber != null\">`plot_number` = #{plotNumber}, </if>" + 
                    "<if test=\"plotArea != null\">`plot_area` = #{plotArea}, </if>" + 
                    "<if test=\"soilClassification != null\">`soil_classification` = #{soilClassification}, </if>" + 
                    "<if test=\"nutrient != null\">`nutrient` = #{nutrient}, </if>" + 
                    "<if test=\"plantingTime != null\">`planting_time` = #{plantingTime}, </if>" + 
                    "<if test=\"count != null\">`count` = #{count}, </if>" + 
                    "<if test=\"plantSpacing != null\">`plant_spacing` = #{plantSpacing}, </if>" + 
                    "<if test=\"beforeOld != null\">`before_old` = #{beforeOld}, </if>" + 
                    "<if test=\"old != null\">`old` = #{old}, </if>" + 
                    "<if test=\"preMu != null\">`pre_mu` = #{preMu}, </if>" + 
                    "<if test=\"production != null\">`production` = #{production}, </if>" + 
                    "<if test=\"frameShape != null\">`frame_shape` = #{frameShape}, </if>" + 
                    "<if test=\"tree != null\">`tree` = #{tree}, </if>" + 
                    "<if test=\"seedId != null\">`seed_id` = #{seedId}, </if>" + 
          					"</set>" + 
					"where plot_id = #{plotId}"+
			"</script>")
	int update(PlotDO plot);
	
	@Delete("delete from tb_plot where plot_id =#{plotId}")
	int remove(Integer plot_id);
	
	@Delete("<script>"+ 
			"delete from tb_plot where plot_id in " + 
					"<foreach item=\"plotId\" collection=\"array\" open=\"(\" separator=\",\" close=\")\">" + 
						"#{plotId}" + 
					"</foreach>"+
			"</script>")
	int batchRemove(Integer[] plotIds);
}
